<?php
require_once($_SERVER['DOCUMENT_ROOT'] . '/all.conf.php');
require_once(__PHY_LIB.'/inc/page.user.inc.php');

$rReq = validate($_REQUEST, 'action:e[edit,update]');
$rMsg = array();

if ('update' == $rReq['action']) {
	do {
		$rP = validate($_POST, 'old_pswd:u|new_pswd:u|rpt_pswd:u');
		if (!$rP['old_pswd']) { $rMsg['old_pswd'] = '旧的密码为空'; }
		if (!$rP['new_pswd']) { $rMsg['new_pswd'] = '新的密码为空'; }
		if (!$rP['rpt_pswd']) { $rMsg['rpt_pswd'] = '重复密码为空'; }
		if ($rP['new_pswd'] != $rP['rpt_pswd']) { $rMsg['rpt_pswd'] = '重复密码不相同'; }
		if (0 < sizeof($rMsg)) { $rMsg['action'] = '保存失败。'; break; }
		$oUser = new uUser($_The['User']['id']);
		if ($oUser->pswdEncode($rP['old_pswd']) != $oUser->get('pswd')) {
			$rMsg['old_pswd'] = '旧密码错误'; break;
		}
		$oUser->set('pswd', $oUser->pswdEncode($rP['new_pswd']));
		$oUser->update();
		$rMsg['action'] = '密码修改完毕'; break;
	} while (false);
}

$oTpl->assign('rMsg', $rMsg);
$oTpl->assign('sAction', $rReq['action']);
$oTpl->display(dirname(__FILE__).'/'.basename(__FILE__, '.php').'.tpl');
?>
